#!/bin/bash

check_os_version(){
    release=$(rpm -qa |grep release|awk -F'-' '{print $1}'|egrep "centos|redhat|openEuler|neokylin|kylin|uos|almalinux|ctyunos|bclinux" |head -1)
    if [ $release == "redhat" ];then
             version=$(rpm -qa|grep redhat-release |awk -F\. '{print $(NF-1)}' |sed 's/el//g' |head -1)
    elif [ $release == "centos" ];then
             version=$(rpm -qa |grep centos-release |awk -F\- '{print $3}' |head -1)
    elif [ $release == "neokylin" ];then
             version=$(rpm -qa |grep neokylin-release |awk -F '[-.]' '{print $4}' |head -1)
    elif [ "${release}" == "bclinux" ];then
             version=$(rpm -qa |grep bclinux-release |awk -F '-' '{print $3}'|awk -F '.' '{print $1}')
    elif [ "${release}" == "ctyunos" ];then
             version=$(if [ `rpm -qa |grep ctyunos-release |wc -l` -gt 0 ];then echo "7";fi )
    elif [ "${release}" == "almalinux" ];then
             version=$(if [ `rpm -qa |grep almalinux-release-8 |wc -l` -gt 0 ];then echo "7";fi)
    elif [ "${release}" == "kylin" ];then
             version=$(if [ `rpm -qa |grep kylin-release-10 |wc -l` -gt 0 ];then echo "7";fi)
    elif [ "${release}" == "uos" ];then
             version=$(if [ `rpm -qa |grep uos-release |wc -l` -gt 0 ];then echo "8";fi)
    elif [ "${release}" == "openEuler" ];then
             version=$(if [ `rpm -qa |grep openEuler-release |wc -l` -gt 0 ];then echo "7";fi )
    else
        echo "not support,install script exit..."
        exit 0
    fi

    echo "${version}"
}

check_os_type(){
    release=$(rpm -qa |grep release|awk -F'-' '{print $1}'|egrep "centos|redhat|openEuler|neokylin|kylin|uos" |head -1)
    echo "${release}"
}

set_pythonpath(){
    if [ -s /usr/local/python_el${version}_3.6 ];then
        tar xf ~/python_el6_3.6.tar.gz -C /usr/local/
    fi
    py27=/usr/local/python_el6_3.6/bin
    sed -i 's/^PATH=/#PATH=/g;s/^export PATH/#export PATH/g' ~/.bash_profile
    echo "PATH=$py27:\$PATH:\$HOME/bin:/sbin:/usr/bin">>~/.bash_profile
    echo "export PATH">>~/.bash_profile

    rm -rf ~/python_el6_3.6.tar.gz
}

set_pythonpath_eight(){
    if [ -s /usr/local/python_el8_3.6 ];then
        tar xf ~/python_el8_3.6.tar.gz -C /usr/local/
    fi
    py27=/usr/local/python_el8_3.6/bin
    sed -i 's/^PATH=/#PATH=/g;s/^export PATH/#export PATH/g' ~/.bash_profile
    echo "PATH=$py27:\$PATH:\$HOME/bin:/sbin:/usr/bin">>~/.bash_profile
    echo "export PATH">>~/.bash_profile

    rm -rf ~/python_el8_3.6.tar.gz
}

$1


